/*
 * system.c
 *
 *  Created on: 2017年7月3日
 *      Author: zjm
 */

#include "../mongoose.h"
#include "db.h"

int null(struct mg_connection *nc,struct http_message *hm)
{
	mg_printf(nc, "null");

	return 0;
}

int get_system_arch(struct mg_connection *nc)
{
	mg_printf(nc, "armv5");

	return 0;
}


int get_device_code(struct mg_connection *nc)
{
	dbFile db;
	char *rest = "undefined";

	db_open("/data/data.db",&db);

	dbStart(&db);

	dbSql(&db,"select id from t_config;");

	if(dbStep(&db) == SQLITE_ROW){
		rest = dbGetResultString(&db,0);
	}

	mg_printf_html_escape(nc,"%s",rest);

	dbDone(&db);

	db_close(&db);

	return 0;
}

int get_system_version(struct mg_connection *nc)
{
	mg_printf_html_escape(nc,"Linux 3.14+");

	return 0;
}

int get_config_ip(struct mg_connection *nc)
{
	mg_printf_html_escape(nc,"192.168.1.122");

	return 0;
}

int get_config_netmask(struct mg_connection *nc)
{
	mg_printf_html_escape(nc,"255.255.255.0");
	return 0;
}

int get_config_gateway(struct mg_connection *nc)
{
	mg_printf_html_escape(nc,"192.168.1.1");
	return 0;
}

int get_config_dns_primary(struct mg_connection *nc)
{
	mg_printf_html_escape(nc,"192.168.1.1");
	return 0;
}

int get_config_dns_secondary(struct mg_connection *nc)
{
	mg_printf_html_escape(nc,"8.8.8.8");
	return 0;
}
